<template>
	<div class="system-user-container layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<div class="system-dialog-search mb15">
				<span class="p_el_input">门禁时段名称：<el-input size="default" v-model="state.pagenation.name"
						placeholder="请输入门禁时段名称" clearable style="width:200px" />
				</span>
				<el-button size="default" type="primary" text class="ml10" @click="getTableData">
					<el-icon style="font-size: 20px !important;">
						<ele-Search />
					</el-icon>
					{{ $t('message.btnName.search') }}
				</el-button>
				<el-button size="default" style="margin-left: 50px !important;" type="success" class="ml10"
					@click="onOpenAddDialog('add')">
					<el-icon>
						<ele-FolderAdd />
					</el-icon>
					{{ $t('message.btnName.addRow') }}
				</el-button>
			</div>
			<el-table border :data="state.list" v-loading="state.loading" style="width: 100%">
				<el-table-column prop="id" label="序号" width="70" align="center">
					<template #default="{ $index }">
						{{ $index + 1 }}
					</template>
				</el-table-column>
				<el-table-column prop="name" label="门禁时段名称" show-overflow-tooltip />
				<el-table-column label="周日" align="center">
					<el-table-column label="时段1" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v0StartOnA }} - {{ scope.row.v0EndOnA }}
						</template>
					</el-table-column>
					<el-table-column label="时段2" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v0StartOnB }} - {{ scope.row.v0EndOnB }}
						</template>
					</el-table-column>
					<el-table-column label="时段3" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v0StartOnC }} - {{ scope.row.v0EndOnC }}
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="周一" align="center">
					<el-table-column label="时段1" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v1StartOnA }} - {{ scope.row.v1EndOnA }}
						</template>
					</el-table-column>
					<el-table-column label="时段2" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v1StartOnB }} - {{ scope.row.v1EndOnB }}
						</template>
					</el-table-column>
					<el-table-column label="时段3" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v1StartOnC }} - {{ scope.row.v1EndOnC }}
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="周二" align="center">
					<el-table-column label="时段1" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v2StartOnA }} - {{ scope.row.v2EndOnA }}
						</template>
					</el-table-column>
					<el-table-column label="时段2" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v2StartOnB }} - {{ scope.row.v2EndOnB }}
						</template>
					</el-table-column>
					<el-table-column label="时段3" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v2StartOnC }} - {{ scope.row.v2EndOnC }}
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="周三" show-overflow-tooltip align="center">
					<el-table-column label="时段1" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v3StartOnA }} - {{ scope.row.v3EndOnA }}
						</template>
					</el-table-column>
					<el-table-column label="时段2" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v3StartOnB }} - {{ scope.row.v3EndOnB }}
						</template>
					</el-table-column>
					<el-table-column label="时段3" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v3StartOnC }} - {{ scope.row.v3EndOnC }}
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="周四" show-overflow-tooltip>
					<el-table-column label="时段1" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v4StartOnA }} - {{ scope.row.v4EndOnA }}
						</template>
					</el-table-column>
					<el-table-column label="时段2" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v4StartOnB }} - {{ scope.row.v4EndOnB }}
						</template>
					</el-table-column>
					<el-table-column label="时段3" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v4StartOnC }} - {{ scope.row.v4EndOnC }}
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="周五" show-overflow-tooltip align="center">
					<el-table-column label="时段1" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v5StartOnA }} - {{ scope.row.v5EndOnA }}
						</template>
					</el-table-column>
					<el-table-column label="时段2" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v5StartOnB }} - {{ scope.row.v5EndOnB }}
						</template>
					</el-table-column>
					<el-table-column label="时段3" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v5StartOnC }} - {{ scope.row.v5EndOnC }}
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="周六" show-overflow-tooltip align="center">
					<el-table-column label="时段1" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v6StartOnA }} - {{ scope.row.v6EndOnA }}
						</template>
					</el-table-column>
					<el-table-column label="时段2" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v6StartOnB }} - {{ scope.row.v6EndOnB }}
						</template>
					</el-table-column>
					<el-table-column label="时段3" align="center" show-overflow-tooltip>
						<template #default="scope">
							{{ scope.row.v6StartOnC }} - {{ scope.row.v6EndOnC }}
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="操作" fixed="right" width="100">
					<template #default="scope">
						<el-button :disabled="scope.row.notEdit === 1" size="small" text type="primary"
							@click="onOpenEditDialog('edit', scope.row.code)">	{{ $t('message.btnName.edit') }}</el-button>
						<el-button :disabled="scope.row.notDel === 1" size="small" text type="danger"
							@click="onRowDel(scope.row.id)">	{{ $t('message.btnName.remove') }}</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
				:pager-count="5" :page-sizes="[10, 50, 200, 800]" v-model:current-page="state.pagenation.pageNum" background
				v-model:page-size="state.pagenation.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="state.pagenation.total" />
		</el-card>
		<dialogComponent ref="editDialogRef" @refresh="getTableData()" />
	</div>
</template>

<script setup lang="ts" name="index">
import { defineAsyncComponent, reactive, onMounted, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { useAccessTimezonePageApi, useAccessTimezoneDeleteApi } from '/@/api/access/timezone';
import moment from 'moment'
// 引入组件
const dialogComponent = defineAsyncComponent(() => import('./editDialog.vue'));


// 定义变量内容
const editDialogRef = ref();
const state = reactive({
	list: [],
	loading: false,
	pagenation: {
		total: 0,
		pageNum: 1,
		pageSize: 10,
		name: ''
	},
	printName: '打印示例'
});

// 初始化表格数据
const getTableData = () => {
	state.loading = true;
	useAccessTimezonePageApi(state.pagenation).then(({ content }) => {
		state.list = content.list
		state.pagenation.total = content.total
		state.pagenation.pageNum = content.pageNum
		state.pagenation.pageSize = content.pageSize
	}).then(() => {
		state.loading = false;
	}).catch(() => {
		ElMessage.error('查询失败')
	})
};
// 打开新增弹窗
const onOpenAddDialog = (option: string) => {
	editDialogRef.value.openDialog(option);
};
// 打开修改弹窗
const onOpenEditDialog = (option: string, code: string) => {
	editDialogRef.value.openDialog(option, code);
};
// 删除
const onRowDel = (id: number) => {
	ElMessageBox.confirm(`此操作将永久删除，是否继续?`, '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(() => {
			useAccessTimezoneDeleteApi(id).then(() => {
				ElMessage.success('删除成功');
			})
			getTableData();
		})
};
// 分页改变
const onHandleSizeChange = (val: number) => {
	state.pagenation.pageSize = val;
	getTableData();
};
// 分页改变
const onHandleCurrentChange = (val: number) => {
	state.pagenation.pageNum = val;
	getTableData();
};
// 页面加载时
onMounted(() => {
	getTableData();
});
</script>

<style scoped lang="scss">
.system-user-container {
	:deep(.el-card__body) {
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow: auto;

		.el-table {
			flex: 1;
		}
	}
}
</style>
